import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_base_widget/code2/second_page.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'first_page.dart';


//静态路由配置
void main() => runApp(MyApp3());

//定义根目录Widget
class MyApp3 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: const [
        //初始化默认的 Material 组件本地化
        GlobalMaterialLocalizations.delegate,
        //初始化默认的 通用 Widget 组件本地化
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      //当前区域，如果为null则使用系统区域一般用于语言切换
      //传入两个参数，语言代码，国家代码
      //这里配制为中国
      locale: const Locale('zh', 'CN'),
      //定义当前应用程序所支持的语言环境
      supportedLocales: const [
        Locale('en', 'US'), // English 英文
        Locale('zh', 'CN'), // 中文
      ],
      routes: {
        //默认页面
        "/": (BuildContext context) => Exam204HomePage(),
      },
    );
  }
}
///代码清单2-8 Scaffold中 AppBar基本使用
///代码路径 lib/code2/code204_Scaffold_AppBar.dart
class Exam204HomePage extends StatefulWidget {
  @override
  State<Exam204HomePage> createState() => _Exam204HomePageState();
}

class _Exam204HomePageState extends State<Exam204HomePage> {
  @override
  Widget build(BuildContext context) {
    //Scaffold 用来搭建页面的主体结构
    return Scaffold(
      //页面的头部
      appBar: AppBar(
        //左侧按钮 会覆盖默认的左侧回退按钮
        leading: IconButton(
          icon: const Icon(Icons.close),
          onPressed: () {},
        ),
        //中间显示的内容
        title: const Text("这里是title"),
        // title 内容居中
        centerTitle: true,
        //右侧显示的内容
        actions: [
          IconButton(
            icon: Icon(Icons.share),
            onPressed: () {},
          ),
          IconButton(
            icon: Icon(Icons.message),
            onPressed: () {},
          ),
          IconButton(
            icon: Icon(Icons.more_horiz_outlined),
            onPressed: () {},
          ),
        ],
      ),
      //页面的主内容区
      body: Center(child: Text("测试页面")),
    );
  }
}
